﻿
namespace LAPI.Core
{
    public static class StringExtension
    {
        public static string Nvl(this string str, string val, string defaultValue="")
        {
            return val != null ? val : defaultValue;
        }


        public static string GetFieldValue(System.Type type, System.String FieldName )
        {
            // Get the members associated with MyClass1.
            System.Reflection.MemberInfo[] myMembers = type.GetMembers();

            // Display the attributes for each of the members of MyClass1.
            for (int i = 0; i < myMembers.Length; i++)
            {
                if (myMembers[i].Name.Equals(FieldName))
                {
                    System.Object[] myAttributes = myMembers[i].GetCustomAttributes(true);

                    foreach (var item in myAttributes)
                    {
                        if (item is LAPI.Core.FieldValueAttribute)
                        {
                            return ((LAPI.Core.FieldValueAttribute)item).FieldValue;
                        }
                    }
                }
            }

            return "Not implemented";
        }
    }

    public class FieldValueAttribute : System.Attribute
    {
        #region Properties
        public string FieldValue { get; protected set; }
        #endregion

        #region Constructor
        public FieldValueAttribute(string value)
        {
            this.FieldValue = value;
        }
        #endregion
    }
}